var arr = [
  1,2,1,
  {a: 1, b: 2},
  {b: 2, a: 1},
  {a: 1, b: 2, c: {b: 2, a: 1}},
  {b: 2, a: 1,  c: {a: 1, b: 2}},
]

// 最基本的写法
var arr1 = [1,1,2,9,3,4,6,5,4,3,2,]
function getNewArr(arr) {
  const newArr = [... new Set(arr)];
  for(let i = 0; i < newArr.length; i++) {
    for(let j = i + 1; j < newArr.length; j++) {
      if (newArr[i] === newArr[j]) {
        newArr.splice(j, 1)
        j--;
      }
    }
  }
  return newArr
}
console.log(getNewArr(arr1))



const isObject = val => typeof val === 'object' && val !== null;
function equals(val1, val2) {
  if (!isObject(val1) || !isObject(val2)) 
  // return val1 === val2; 一般写法
  // 考虑 +0, -0 和 NaN 
  return Object.is(val1, val2);
  if (val1 === val2) return true;
  const val1Keys = Object.keys(val1);
  const val2Keys = Object.keys(val2);
  // 比较长度
  if(val1Keys.length !== val2Keys.length) return false;
  for(let key in val1) {
    if (!val2Keys.includes(key)) {
      return false
    }
    const res = equals(val1[key], val2[key])
    if (!res) return false
  }
  return true;
}

//
function getNewArr2(arr) {
  const newArr = [... new Set(arr)];
  for(let i = 0; i < newArr.length; i++) {
    for(let j = i + 1; j < newArr.length; j++) {
      if (equals(newArr[i], newArr[j])) {
        newArr.splice(j, 1)
        j--;
      }
    }
  }
  return newArr
}
// console.log(getNewArr2(arr))

function filterRepeat(arr) {
  var newArr = [...new Set(arr)];
  
}